home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 May: Tool Chest / Developer CD Series Tool Chest (Apple Computer)(May 1999).iso / Tool Chest / Development Kits / MPW Related / MPW Script Tips 1.1.1 / Sample Scripts / Hexify < prev    next >
Encoding:
Text File  |  1991-08-16  |  6.9 KB  |  214 lines  |  [TEXT/MPS ]

  1. #----------------------------------------------------------------------------------------------------------------------------------------------------
  2. #    Hexify
  3. #    MPW Shell Script
  4. #    Written by Gina Cherry • August 16, 1991
  5. #    Copyright:    © 1991 by Apple Computer, Inc., all rights reserved.
  6. #
  7. #    Usage: 
  8. #        Hexify name… [-t textfile] [-d] [-p] [-r]
  9. #
  10. #    Function:
  11. #        This script takes all StuffIt files from a list of one or more directories and all their 
  12. #        subdirectories, and makes them into .hqx files.  
  13. #        If the -d option is specified, Hexify deletes the StuffIt files as it goes.  
  14. #        If the -p option is specified, Hexify prints progress information to standard output.  
  15. #        If the -t option is specified, Hexify prepends the specified text file to each .hqx file.  
  16. #        If the -r options is specified, Hexify removes all special characters from the .hqx file name, 
  17. #        replacing them with the '-' character.  This is useful if the files are to be moved to a UNIX 
  18. #        platform.
  19. #
  20. #    Note: 
  21. #        Directory names should have a ':' at the end.
  22. #----------------------------------------------------------------------------------------------------------------------------------------------------
  23.  
  24. #    Don't exit on error.
  25.     Set Exit 0    
  26.  
  27. #    Initialize option variables.
  28.     Set P ""                                    
  29.     Set D ""                                    
  30.     Set R ""
  31.  
  32. #    Initialize file variables.
  33.     Set dirList ""                        
  34.     Set textFile ""                            
  35.  
  36. #    Loop through parameters.
  37.     Loop
  38.     
  39.     #    Break if no more parameters.
  40.         Break If "{1}" == ""
  41.         
  42.     #    If -d option is specified, want to delete StuffIt files.
  43.         If "{1}" == '-d'
  44.         #    Make sure -d has not already been given as an option.
  45.             If {D} == ""
  46.                 Set D 1
  47.         #    If it has, write error message and exit script.
  48.             Else
  49.                 Echo "### "{0}": Option ∂"{1}∂" multiply defined."
  50.                 Echo "### Usage: Hexify name… [-t textfile] [-d] [-p] [-r]"
  51.                 Exit 1
  52.             End 
  53.         
  54.     #    If -p option is specified, want to write progress information to standard output.    
  55.         Else If "{1}" == '-p'
  56.         #    Make sure -p has not already been given as a parameter.
  57.             If {P} == ""
  58.                 Set P 1
  59.         #    If is has, write error message and exit script.
  60.             Else
  61.                 Echo "### "{0}": Option ∂"{1}∂" multiply defined."
  62.                 Echo "### Usage: Hexify name… [-t textfile] [-d] [-p] [-r]"
  63.                 Exit 1
  64.             End
  65.         
  66.     #    If the -r option is specified, want to remove special characters from the .hqx file name.    
  67.         Else If "{1}" == '-r'
  68.         #    Make sure -r has not already been given as a parameter.
  69.             If {R} == ""
  70.                 Set R 1
  71.         #    If is has, write error message and exit script.
  72.             Else
  73.                 Echo "### "{0}": Option ∂"{1}∂" multiply defined."
  74.                 Echo "### Usage: Hexify name… [-t textfile] [-d] [-p] [-r]"
  75.                 Exit 1
  76.             End
  77.     
  78.     #    If the -t option is specified, want to prepend a text file to the .hqx file.        
  79.         Else If "{1}" == '-t'
  80.         #    Make sure -t has not already been given as a parameter.
  81.             If {textFile} == ""
  82.                 Set T 1
  83.             #    Get next parameter, which should be the name of a text file.
  84.                 Shift 1
  85.             #    If there is no next parameter, write error message and exit script.
  86.                 If "{1}" == ""
  87.                     Echo "### {0}: Option ∂"{1}∂" must be followed by a file name."
  88.                     Echo "### Usage: Hexify name… [-t textfile] [-d] [-p] [-r]"
  89.                     Exit 1
  90.             #    Otherwise set textFile to the next parameter.
  91.                 Else
  92.                     Set textFile "{1}"
  93.                 End
  94.         #    If -t has already been given, write error message and exit script.
  95.             Else
  96.                 Echo "### "{0}": Option ∂"{1}∂" multiply defined."
  97.                 Echo "### Usage: Hexify name… [-t textfile] [-d] [-p] [-r]"
  98.                 Exit 1
  99.             End
  100.         
  101.     #    Check for bad options.    
  102.         Else If "{1}" =~ /∂-≈/ || "{1}" == '-'
  103.             Echo "### {0}: Option ∂"{1}∂"  is not an option"
  104.             Echo "### Usage: Hexify name… [-t textfile] [-d] [-p]"
  105.             Exit 1
  106.     
  107.     #    Otherwise, assume the parameter is a file or directory name, and add to list.        
  108.         Else 
  109.             Set dirList "{dirList} '{1}'"
  110.         End >> Dev:StdErr
  111.         
  112.     #    Get next parameter.
  113.         Shift 1
  114.     End 
  115.  
  116. #    If there are no files or directories in the list, write error message and exit script.
  117.     If "{dirList}" == ""
  118.         Echo "### {0}: Must specify a directory to hexify."
  119.         Echo "### Usage: Hexify name… [-t textfile] [-d] [-p]"
  120.         Exit 1
  121.     End >> Dev:StdErr
  122.  
  123. #    Check if -t options was specified.
  124.     If {T}    
  125.     #    Open the text file to be prepended to the hexified files.  Discard diagnostic output.
  126.         Open -t "{textFile}" ≥ Dev:Null        
  127.     #    If the Open command failed, write error message and exit script.
  128.         If {status} != 0
  129.             Echo "### {0}: {textFile} is not a valid file"
  130.             Echo "### Usage: Hexify name… [-t textfile] [-d] [-p]"
  131.             Exit 2
  132.         End >> Dev:StdErr
  133.     #    Select the entire text file.
  134.         Find •:∞ "{textFile}"    
  135.     #    Copy text file to clipboard.
  136.         Copy § "{textFile}"        
  137.     #    Close the text file; don't save changes.
  138.         Close -n "{textFile}"
  139.     End
  140.  
  141. # Save value of NewWindowRect to restore later.
  142.     Set OldWindowRect "{NewWindowRect}"        
  143.     
  144. # Want the workspace window to be small.
  145.     Set NewWindowRect 0,0,100,100
  146.     
  147. #    Open a temporary workspace.
  148.     Open -n -t {0}.Temp    
  149.     
  150. # Restore value of NewWindowRect.
  151.     Set NewWindowRect "{OldWindowRect}"    
  152.  
  153. #    Loop through the list of files and directories.
  154.     For dir in {dirList}
  155.     
  156.         If !"`Exists "{dir}"`"
  157.             Echo "# {0}: Unable to get information on {dir}" >> Dev:StdErr
  158.             Continue
  159.         End
  160.     
  161.     #    Set variable theFiles to a list of the full pathnames of all StuffIt files in dir and all subfolders 
  162.     #    of dir.  Discard diagnostic output.  The Echo and Continue commands in parentheses will be
  163.     #    executed if and only if the Files command fails.  In that case, print an error message and
  164.     #    continue with the next iteration of the loop.
  165.         Set theFiles "`Files -r -s -t SIT! -f "{dir}"≥ Dev:Null`"
  166.             
  167.     #    Loop through files in variable theFiles.
  168.         For fName in {theFiles}
  169.         
  170.         #    Create a new file name, ending in.hqx.
  171.             #    Write the current file name to the temporary file, overwriting existing text.
  172.                 Echo {fName} > {0}.Temp
  173.             #    Position cursor at the beginning of the temporary file.
  174.                 Find • {0}.Temp
  175.             #    Replace the string '.sit' appearing at the end of a line with the string '.hqx'.
  176.                 Replace /.sit∞/ ".hqx" {0}.Temp
  177.             #    Set the variable tempName to the new file name.
  178.                 Set tempName "`Catenate {0}.Temp`"    
  179.             
  180.         #    If the -r option was specified, remove special characters from the file name using the tool
  181.         #    FTPName.
  182.             If "{R}"
  183.                 Set hqxName "`FTPName "{tempName}"`"    
  184.             Else
  185.                 Set hqxName "{tempName}"
  186.             End
  187.             
  188.         #    Convert file to hex using BinHex tool, sending output to a file with the new hqxName.
  189.             BinHex "{fName}" "{hqxName}"
  190.             
  191.         #    If -p option was specified write progress information to standard output.
  192.             If {P}                                    
  193.                 Echo "{fName} -> {hqxName}"            
  194.             End
  195.             
  196.         #    If the -d option was specified, delete the StuffIt file that was just hexified.
  197.             If {D}                                    
  198.                 Delete -y "{fName}"                    
  199.             End
  200.             
  201.         #    If the -t option was specified, open the hexified file and prepend the contents of the 
  202.         #    clipboard to it.  Close and save changes.
  203.             If {T}                                    
  204.                 Open -t "{HqxName}"
  205.                 Paste • "{HqxName}"                    
  206.                 Close -y "{HqxName}"
  207.             End
  208.         End
  209.     End
  210.  
  211. #    Close the temporary file; don't save changes
  212.     Close -n {0}.Temp
  213.  
  214.